<template>
	<view>
		<uni-datetime-picker v-model="queryParams.betweenTime" start-placeholder="start" end-placeholder="end"
			:clear-icon="false" type="daterange" rangeSeparator="--" @change="change" />
		<view v-for="(item, index) in reportList" :key="index">
			<ListItem title="class Type">
				<template #date>
					<text>{{item.class_date}}</text>
				</template>
				<template #connect>
					<p>{{item.stu.user_id}} | {{item.stu.real_name}}</p>
					<p>{{item.topics}}</p>
					<p>{{item.learn_time}}</p>
				</template>
			</ListItem>
		</view>
		<empty v-show="reportList.length==0"></empty>
	</view>
</template>

<script>
	import common from "@/api/common.js"
	import ListItem from '@/components/basicListItem/ListItem/ListItem.vue'
	export default {
		components: {
			ListItem,
		},
		data() {
			return {
				queryParams: {
					page: 1,
					betweenTime: []
				},
				reportList: [],
				lastPage: ''
			}
		},
		// 底部上拉刷新
		onReachBottom() {
		  if (this.lastPage > 1 && this.queryParams.page <= this.lastPage) {
		    uni.showLoading({
		      title: 'Loading'
		    });
		    setTimeout(() => {
		      uni.hideLoading();
		    }, 2000);
		    this.queryParams.page++;
		    this.getList();
		  } else {
		    uni.showToast({
		      title: 'nomoreText',
		      icon: 'none'
		    });
		  }
		},
		onLoad() {
			this.getList()
		},
		methods: {
			getList() {
			  common.getReportList(this.queryParams).then((res) => {
			    if (this.queryParams.page === 1) {
			      this.reportList = res.data.list.data;
			    } else {
			      this.reportList = this.reportList.concat(res.data.list.data);
			    }
			    this.lastPage = res.data.list.last_page;
			  });
			},
			change(e) {
				uni.showLoading({
					title: 'Loading'
				});
				this.queryParams.page = 1; // 重置页码为1
				this.reportList = []; // 清空数组
				this.debounce(() => {
					this.getList()
				}, 500);
			}
		}
	}
</script>

<style scoped>
	page {
		background-color: #F5F5F5;
	}
	::v-deep .uni-date-x--border {
		border: none !important;
	}
	
	::v-deep .uni-date-x {
		border: none !important;
		background: #FFFFFF;
		box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(174, 174, 174, 0.16);
		margin-bottom: 25rpx;
		border-radius: 100rpx;
		color: #1C2026;
		text-align: center;
		line-height: 66rpx;
	}
</style>